# Initializing Common Variables ###############################################

DEBUG=-D_DEBUG

CC=gcc
LD=gcc

WORKING_DIR=.
SRC_DIR=$(WORKING_DIR)/src
INC_DIR=$(WORKING_DIR)/include
BIN_DIR=$(WORKING_DIR)/bin
LIB_DIR=$(WORKING_DIR)/lib
LIB_NAME=essentialc

# Module-Related Macro Definitions ############################################

UTIL=esc_util
UTIL_SRC_FILES=esc_common.c esc_list.c esc_mem.c esc_queue.c esc_signal.c \
	esc_stack.c esc_string.c esc_table.c esc_thread.c 
UTIL_INC_FILES=esc_common.h esc_list.h esc_mem.h esc_queue.h esc_signal.h \
	esc_stack.h esc_string.h esc_table.h esc_thread.h
UTIL_OBJ_FILES=$(UTIL_SRC_FILES:%.c=%.o)
UTIL_SRC=$(UTIL_SRC_FILES:%.c=$(SRC_DIR)/%.c)
UTIL_INC=$(UTIL_INC_FILES:%.h=$(INC_DIR)/%.h)	
UTIL_OBJ=$(UTIL_OBJ_FILES:%.o=$(SRC_DIR)/%.o)
UTIL_LIBS=-lpthread
UTIL_LINK=$(UTIL_OBJ)
#UTIL_OUT=$(LIB_DIR)/lib$(LIB_NAME).so.1.0
UTIL_OUT=$(LIB_DIR)/lib$(LIB_NAME).dylib

# Compiler and Linker Variables ###############################################

INCLUDE_FLAGS=-I$(INC_DIR)

LIB_FLAGS=

DEFINE_FLAGS=$(XML_DEFINES) $(GC_DEFINES) $(PCRE_DEFINES)

CFLAGS=-gfull -fPIC -std=c99 -Wall $(DEBUG) $(DEFINE_FLAGS) $(INCLUDE_FLAGS)
#LDFLAGS=-shared -Wl,-soname,lib$(LIB_NAME).so.1 $(LIB_FLAGS)
LDFLAGS=-dylib -flat_namespace -undefined suppress $(LIB_FLAGS)

# Primary Targets and Dependencies ############################################

OBJ=$(UTIL_OBJ)

OUTPUT=$(UTIL_OUT)

all: $(OUTPUT)

clean: clean-obj clean-output

clean-obj:
	$(RM) $(OBJ)

clean-output:
	$(RM) $(OUTPUT)


# Module-Related Output Dependencies ##########################################

$(UTIL_OUT): $(UTIL_SRC) $(UTIL_INC) $(UTIL_OBJ) 
	$(LD) $(LDFLAGS) $(UTIL_LIBS) $(UTIL_LINK) -o $(UTIL_OUT) 

$(UTIL_OBJ): $(UTIL_SRC) $(UTIL_INC)
